package com.gzyj.jtt808.v2019.protocol;

import com.gzyj.jtt808.v2013.enums.JT808TerminalResult;
import com.gzyj.jtt808.v2019.enums.BusinessDataType;
import com.gzyj.jtt808.v2019.Package;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;

/**
 * 平台通用应答
 *
 * @author lhj
 */
@Data
public class JTT808_0x8001 extends Package implements Serializable {

    private Integer MsgNum;//应答消息流水号
    private Integer AckMsgId;//应答消息Id

    private JT808TerminalResult Result;//返回结果

    public JTT808_0x8001() {
        super(BusinessDataType.平台通用应答.getCode());
    }

    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeShort(this.MsgNum);
        buf.writeShort(this.AckMsgId);
        buf.writeByte(this.Result.getCode());
    }

    @Override
    public JTT808_0x8001 decodeImpl(ByteBuf buf) {
        this.MsgNum = buf.readUnsignedShort();
        this.AckMsgId = buf.readUnsignedShort();
        this.Result = JT808TerminalResult.find(Byte.toUnsignedInt(buf.readByte()));
        return this;
    }


}
